package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constants.AvatarMessageConstants;
import com.qk.domain.clue.CluDO;
import com.qk.domain.clue.ClueDO;
import com.qk.dto.clue.ClueDTO;
import com.qk.dto.clue.ClueListDTO;
import com.qk.dto.clue.UpdateClueInfoDTO;
import com.qk.dto.clue.poolDTO;
import com.qk.entity.Clue;
import com.qk.entity.FakeClueDTO;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/clues")
public class ClueController {
    @Autowired
    private ClueService clueService;

    @GetMapping("/pool")
    public Result poolCluelsit(poolDTO dto){
        PageResult<CluDO> pageResult = clueService.poolCluelsit(dto);
        return Result.success(pageResult);
    }

    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto) {
        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    @PutMapping("/false/{id}")
    public Result setClueToFake(@PathVariable Integer id,
                                @RequestBody FakeClueDTO dto) {
        dto.setId(id);
        clueService.setClueToFake(dto);
        return Result.success();
    }

    @PutMapping("toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id) {
        ClueVO vo = clueService.getClueInfoById(id);
        return Result.success(vo);
    }

    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder().id(clueId).userId(userId).updateTime(LocalDateTime.now()).status(AvatarMessageConstants.WAIT_FOLLOW_UP).build());
        return Result.success();
    }

    @GetMapping
    public Result list(ClueListDTO dto) {
        PageResult<ClueDO> result = clueService.clueListMp(dto);
        return Result.success(result);
    }

    @PostMapping
    public Result addRule(@RequestBody ClueDTO dto) {
        clueService.addClue(dto);
        return Result.success();
    }

}